    <template>
	<div class="vue_app">
		<my-header :title="'线下订单'" :hasTitle="true" :hasBack="true" :goBack="goBack"></my-header>
		<div class="content">
			<!--商品列表-->
			<div class="aui-content choose_list">
				<ul class="aui-list aui-media-list">
					<li class="aui-list-item iscroll_list">
						<div id="co_orderGoods" class="aui-media-list-item-inner scroller_list" v-if="goodsList">
							<div class="aui-list-item-media" v-for="(item,index) in goodsList" :key="index">
								<div class="goodsTopShow" v-if="item.buyType == 2 || item.buyType == 3" :class="{goodsTopShowBackY:item.buyType == 2,goodsTopShowBackR:item.buyType == 3}">
									{{item.buyType == 2?'加价购':'赠品'}}
								</div>
								<img v-lazy="item.goodsImg || 'static/image/demo2.png'" style="height: 100%;width: 100%;"/>
								<em style="background:#EF5423;opacity: 0.6;">x{{item.goodsType == 7?'1':item.goodsNum}}</em>
							</div>
							<!--为了让用户能看到最后一个盒子-->
							<div class="aui-list-item-media" >
								
							</div>
						</div>
					</li>
				</ul>
				<div class="aui-list-item-arrow statistics">   <!-- num-->
					<p>共<span id="co_totalPiece" style="padding-top: 0.5rem;">{{num}}</span>件</p>
					<!--<p id="co_totalPackage">1个包裹</p>-->
					<!--<p id="co_totalPackage">常规配送</p>-->
				</div>
			</div>
			 <div style="margin-bottom: 0.75rem;margin-top: -0.75rem;">
			 	<!--v-if="sendNameArr && sendNameArr.length != 0" -->
				<div class="aui-list-item-arrow01 server_show"  v-if="sendNameArr && sendNameArr.length != 0" style="background-color: #fff2f2;padding: 0.2rem 0.5rem;">
			        <div style="margin-left: 15;text-align: left;" class="aui-list-item-arrow_2">
						<h4>[赠品]</h4>
						<dl>
							<dd v-for="(item,index) in sendNameArr" :key="index">   <!--v-for="(item,index) in sendNameArr" -->
								<font>{{item}}</font>   <!--赠品名称  --> 
								<!--<span>¥9.8×1</span>-->
							</dd>
						</dl>
					</div>
				</div>
		    </div>
			<!--商品列表 end-->
			<!--信息列表-->
			<div class="aui-content aui-margin-b-15">
				<ul class="aui-list aui-list-in">
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-title">商品金额</div>
							<div id="co_totalMoney" class="aui-list-item-right">¥{{goodsTotalMoney?goodsTotalMoney.toFixed(2):'0.00'}} <span v-if="addMoney">(含加工费：¥{{''}})</span></div>
						</div>
					</li>
					<!--<li class="aui-list-item aui-list-item-arrow" v-if="false">
						<div class="aui-list-item-inner" @click="showGiftCard">
							<div class="aui-list-item-title">我的钱包</div>
							<div class="aui-list-item-right" >{{getUseGiftCard?'已选择':''}}</div>
						</div>
					</li>-->
                    <li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-title">活动优惠</div>
							<div id="co_totalMinis" class="aui-list-item-right" v-if="getTicketList && getTicketList.length">{{afterPromTotalMoney?'-':''}}¥{{afterPromTotalMoney?afterPromTotalMoney.toFixed(2):'0.00'}}</div>
							<div id="co_totalMinis" class="aui-list-item-right" v-if="!getTicketList || !getTicketList.length">{{discountMoney?'-':''}}¥{{discountMoney?discountMoney.toFixed(2):'0.00'}}</div>
						</div>
					</li>
					<li class="aui-list-item aui-list-item-arrow">
						<div class="aui-list-item-inner" @click="showCoupon">
							<div class="aui-list-item-title">优惠券</div>																												<!--ticketList-->
							<!-- <div class="aui-list-item-right"><span style="color: #EF5423;padding-right: 0.1rem;" v-if="getTicketList.length === 0 && couponCount">{{couponCount}}</span>{{couponFlag}}</div> -->
                            <div class="aui-list-item-right"><span>{{discountMoneyByCoupon?'-':''}}¥{{discountMoneyByCoupon?discountMoneyByCoupon.toFixed(2):'0.00'}} </span></div>
						</div>
					</li>
					<!-- <li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-title">优惠金额</div>
							<div id="co_totalMinis" class="aui-list-item-right">¥{{discountMoney}}</div>
						</div>
					</li> -->
				</ul>
			</div>
			<!--信息列表 end-->
			<!--<div class="aui-content aui-margin-b-15">
				<ul class="aui-list aui-form-list liuyan">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner" style="align-items:flex-start;">
                        <div class="aui-list-item-label" style="line-height:2rem;">买家留言：</div>
                        <div class="aui-list-item-input">
                            <textarea placeholder="选填：输入留言信息" v-model="myNode" maxlength="100"></textarea>
                        </div>
                    </div>
                </li>
            </ul>
			</div>-->
			<div class="total_sf">
				<h2><span id="co_realpay" >实付金额：¥ {{totalMoney?totalMoney.toFixed(2):'0.00'}}</span> <p style="display: inline;" v-if="false">(省：¥ 1.00)</p> </h2>
				<p>如需发票，请到门店索取</p>
			</div>
			<!--立即下单-->
			<div style="height:4rem;"></div>
			<div class="settle_accounts aui-btn aui-btn-danger aui-btn-block aui-btn-sm" style="height: 2.5rem;line-height: 2.5rem;border-radius: 0px;font-size: 1rem;">
				<div @click.stop="toPay">提交订单</div>
			</div>
			<!--去结算 end-->
		</div>
		<confirm-gift-card ref="giftCard"></confirm-gift-card>
		<confirm-order-pursekey ref="pursekey" :sendOrder="toPay"></confirm-order-pursekey>
		<confirm-coupon ref="coupon" v-if="couponArr && couponArr.length" :couponArr="couponArr" :couponArrHtm="couponArrHtm" :couponMoney="couponM" :money="totalMoney" :getCouponMoney="getSmallData"></confirm-coupon>
		<!-- <confirm-coupon ref="coupon" v-if="couponArr && couponArr.length" :couponArr="couponArr" :couponArrHtm="couponArrHtm" :couponMoney="couponM" :money="Number(totalMoney)" :getCouponMoney="changeCoupon"></confirm-coupon> -->
	</div>
</template>

<script>
	import axios from 'axios';
	import { MessageBox } from '../../ui-components'
	import { Toast } from '../../utils/toast';
	import { mapGetters, mapActions, mapMutations } from "vuex";
	import MyHeader from "../header";
	// import ConfirmCoupon from "../../real-components/ConfirmOrder/ConfirmCoupon";
	import ConfirmCoupon from "../../real-components/ConfirmOrderNew/ConfirmOrderCoupon";
	import ConfirmOrderPursekey from "../../real-components/ConfirmOrder/ConfirmOrderPursekey";
	import ConfirmGiftCard from "../../real-components/ConfirmOrder/ConfirmGiftCard";
	import {xianxia} from "../../config/orderTypeCode";
	import {showLoading, hideLoading} from "../../utils/loading";
	export default {
		props: {
			//         sendOrder:{
			//	           	type:Function,
			//	           	default:()=>{}
			//         },
			//         checkedgoodsList:{
			//         		type:Array,
			//         		default:function(){
			//         			let arr = [];
			//         			return arr
			//         		}
			//         },
			//         normalList:{
			//         		type:Array,
			//         		default:function(){
			//         			let arr = [];
			//         			return arr
			//         		}
			//         },
			//         bigList:{
			//         		type:Array,
			//         		default:function(){
			//         			let arr = [];
			//         			return arr
			//         		}
			//         },
			//         sendMoney:{
			//         		type:Array,
			//         		default:function(){
			//         			let arr = [];
			//         			return arr
			//         		}
			//         },
		},
		components: {
			"my-header": MyHeader,
			"ConfirmCoupon": ConfirmCoupon,
			"confirm-order-pursekey": ConfirmOrderPursekey,
			"ConfirmGiftCard": ConfirmGiftCard
		},
		computed: {
			...mapGetters('wxh', [
				'sessionId',
				'userInfo'
			]),
			...mapGetters('zx', [
				"getTicketList", "getAvailAmount", "getUseGiftCard","getOrderFlag"
			]),
			ticketList() {
//				if(this.getTicketList.length === 0) {
//					if(this.couponCount){
//						this.couponFlag = "组可用";
//					}else{
//						this.couponFlag = '';
//					}
//				} else {
//					this.couponFlag = "已选择";
//				}
//				return this.couponFlag;
			},
			couponM() {
				//				if(Number(this.goodsMoney) - this.couponMoney > 0) {
				//					this.money = Number(this.money) - Number(this.couponMoney);
				//				} else {
				//					this.couponMoney = Number(this.goodsMoney);
				//					this.money = 0;
				//				}
				//				return this.couponMoney;

			},
			totalMoney() {
				return Number(this.goodsPromTotalMoney);
			},
		},
		watch: {
			totalMoney(newVal,oldVal){
				console.log(newVal,oldVal,this.getTicketList.length,'应付金额*--**--*-*-*-*-*-*-*-*-*-应付金额')
//				为确保数据同时渲染在请求完获取金额的接口后再显示优惠券信息
				if(this.getTicketList.length === 0) {
					if(this.couponCount){
						this.couponFlag = "组可用";
					}else{
						this.couponFlag = '';
					}
				} else {
					this.couponFlag = "已选择";
				}
				console.log(this.couponFlag,'应付金额*--**--*-*-*-*-*-*-*-*-*-应付金额2')
//				return this.couponFlag;
				
			}
		},
		data() {
			return {
				mynode: '',
				addMoney: '',
				goodsList: [],
				num: 0,
				orderData: null,
				goodsTotalMoney: 0, // 商品金额
				discountMoney: 0, // 优惠的金额
				discountMoneyByCoupon:0, //优惠券优惠
				goodsPromTotalMoney: 0, //实付金额
				couponArr: null, // 优惠券数组
				couponArrHtm: null, // 用于展示的优惠券数组
				couponFlag: '', //是否选择优惠券
				couponMoney: 0, // 优惠券优惠金额
				money: 0, //总金额
				storeOrderNo: null, // 线下订单号
				shopId: 0, // 线下门店
				moneyWithoutC: 0, //钱包免密金额
				keyall: null, // 钱包密码
				showMask: false, //是否需要用戶輸入密碼
				walletStatus: null, // 是否已经设置钱包密码
				sendNameArr:[], // 赠品名称数组  赠优惠券 赠商品
				couponCount:0 , // 可用优惠券组数
				clickFlag:true,  // 防止两次快速点击 调用两次下单接口
				storeCode:0,
//				moneyWithoutCode: 0, //免密金额
				tokens: null, //token天骄订单传参  防止多次点击提交订单
			}
		},
		methods: {
			...mapMutations('zx', [
				"setUseGiftCard","setOrderFlag","setTicketList"
			]),
			//调试用的  模拟小辉调用数据
			getSmallData(flag){
				let url = window.api.trade_host + "/offLine/confirmOrder";
				if(this.$route.query && this.$route.query.ruCan){
					var obj = this.$route.query.ruCan;
				}
				let params = {
					storeOrderNo: obj.storeOrderNo || '', //pos机订单编号
					storeCode:obj.storeCode || "",
				};
				//优惠券集合
				if(this.getCouponParams()){
					params.qrCode = this.getCouponParams();
				}
				// 是否是第一次调用该接口 true代表第一次调用  false代表第二次开始调用
				params.callFirstTime = flag;
				
				let config = {
					url: url,
					method: 'POST',
					data: params,
					headers: {
						'sessionId': this.sessionId,
					},
				};
				
				axios(config).then((res)=>{
					try {
						if(res.data.returnCode == 0){
							Toast({
									message: res.data.msg,
									// message: "订单已取消",
									duration: 2000,
									type: 'fail'
								});
							setTimeout(()=>{
								this.$router.replace({path:'home'});
							},2000)
							return

						}else if(res.data.returnCode === 2){
							Toast({
								message: res.data.msg,
								// message: "订单已取消",
								duration: 2000,
								type: 'fail'
							});
						}else if(res.data.returnCode === 1){
							this.initData(res);
						}else{
							Toast({
//								message: res.data.msg,
								message: "请完成刚才未完成的订单",
								duration: 2000,
								type: 'fail'
							});
							setTimeout(()=>{
//								this.$router.replace({path:'home'});
								this.$router.push({path:'order',query:{orderStatus:1}});
							},2000)
						}
					}catch(err){
						Toast({
							message: '请求数据异常',
							duration: 2000,
							type: 'fail'
						});
						setTimeout(()=>{
							this.$router.replace({path:'home'});
						},2000)
					}
					
				})
				
			},
			initData(res) {
//				var res = result;
				// if(this.$route.query && this.$route.query.ruCan){
				// 	var res = this.$route.query.ruCan;
				// }
				if(res && res.data.data && res.data.data.length){
					var obj = res.data.data[0];
				}
				
				console.log(res, '路由参数');
				if(res != null) {
                    console.log(obj,obj.storeOrderNo,'线下订单号')
                    // let goodsList = []; //存 主商品，1 为主商品 2 加价购 3 赠品
                    // obj.orderGoods.map((item,index) => {
                    //     if(item.buyType == 1){
                    //         goodsList.push(item);
                    //     }
                    // })
					this.goodsList = obj.orderGoods;
					this.storeOrderNo = obj.storeOrderNo;
					this.shopId = obj.shopId;
//					this.storeCode = obj.storeCode;
					//获取门店编码
					if(obj.storeCode){
						this.storeCode = obj.storeCode;
					}else if(obj.shopId){
						this.storeCode = obj.shopId;
					}
					this.getGoodsNum();//获取总个数
					
//					this.goodsTotalMoney = obj.goodsTotalMoney; //商品总金额  已弃用
//					this.goodsPromTotalMoney = obj.goodsPromTotalMoney; // 实付金额  已弃用
//					this.discountMoney = obj.discountMoney;  //优惠金额 已弃用
					
					this.goodsTotalMoney = obj.promTotalPay; //商品总金额
					this.goodsPromTotalMoney = obj.realPay; // 实付金额
					this.discountMoney = obj.totalMinis;  //优惠金额
                    this.discountMoneyByCoupon = obj.ticketCut; //优惠券优惠
                    this.afterPromTotalMoney = obj.discountCut; //活动优惠
					this.tokens = obj.token;//获取token的值
					this.couponArr = this.newCouponArr(obj.canUsedCouponCodeList, 1);
					this.couponArrHtm = this.newCouponArr(obj.canUsedCouponCodeList, 2);
					
					if(res.data.data[0]){
						// var giftArr = res.data.data[0].giftVOPresentList.concat(res.data.data[0].couponCodePresentList);
						var giftArr = [];
						this.getSendNameArr(giftArr);
					}
					
//					console.log(giftArr,'赠品信息')
//					console.log('首次渲染路由 实付金额', obj.goodsPromTotalMoney);
//					console.log('首次渲染页面展示 实付金额', this.goodsPromTotalMoney);
//					console.log(obj.goodsTotalMoney, 'res.data goodsTotalMoney获取路由参数2');
//					console.log(this.couponArr, 'res.data.data canUsedCouponCodeList获取路由参数3');
//					console.log(obj.discountMoney, 'res.data.data canUsedCouponCodeList 获取路由参数4');
				}

				//				let params = {
				//					storeOrderNo: 0
				//				};
				//
				//				let config = {
				//					url: window.api.trade_host + '/orderOffline/getOrderGoodsInfo',
				//					method: 'GET',
				//					params,
				//					headers: {
				//						'sessionId': this.sessionId
				//					},
				//				};
				//				axios(config).then((res) => {
				//					console.log(res.data.data[0], '后台返回');
				//					if(!res.data.data[0]) {
				//						return;
				//					}
				//					this.orderData = res.data.data[0];
				//					this.goodsList = res.data.data[0].goodsList;
				//					this.goodsNum(); //计算共几件商品
				//				})
			},
			getSendNameArr(giftArr){
				 this.sendNameArr = [];
				 var arr = giftArr;
				 if(arr && arr.length){
				 	for(let i = 0; i < arr.length; i++){
//				 		console.log(arr[i],'礼包');
				 		if(arr[i] != null && arr[i].giftName){
				 			this.sendNameArr.push(arr[i].giftName);
				 		}
				 		if(arr[i] != null && arr[i].couponName){
				 			this.sendNameArr.push(arr[i].couponName);
				 		}
					}
				 }
	        },
			//过滤优惠券数组增加同组标志
			newCouponArr(arr, num) {
				var newArr = [];
				for(let i = 0; i < arr.length; i++) {
					for(let j = 0; j < arr[i].couponCodeList.length; j++) {
						arr[i].couponCodeList[j].relIndex = i;
						newArr.push(arr[i].couponCodeList[j]);
					}
				}
				if(num === 1) {
					return newArr;
				} else if(num === 2) {
					return arr;
				}

			},
			//获取优惠金额
			//			getCouponMoney(el) {

			//				let arr = this.getTicketList;
			//				console.log(arr.length);
			//				var num = 0;

			//				this.money = this.oldGoodsMoney;
			//				console.log(this.money, '总共的金额')
			//				for(let i = 0; i < arr.length; i++) {
			//					console.log(arr[i], '*****’');
			//					if(arr[i].couponType != null) {
			//						if(arr[i].couponType == 1) {
			//							num += Number(this.goodsMoney) * ((10 - Number(arr[i].couponDiscount)) / 10); //打几折
			//							console.log(num, 'ss5869ss');
			//						}
			//						if(arr[i].couponType == 2) {
			//							num += arr[i].couponAmount;
			//							console.log(arr[i].couponAmount, '100')
			//						}
			//						console.log(num, '选完券后')
			//					}
			//				}
			//				if(num == null) {
			//					num = 0;
			//				}
			//
			//				this.couponMoney = Number(num);
			//
			//			},
// 			changeCoupon() {
// //				let url = window.api.trade_host + "/orderOffline/calculatOrderPrice";  // 已废弃
// 				console.log('12gaibian优惠券')
// 				let url = window.api.trade_host + "/offLine/calculatOrderPrice";
// 				let params = {
// 					storeOrderNo: this.storeOrderNo, //pos机订单编号
// //					storeOrderNo: '54564654654654',
// //					shopId: this.shopId //门店编码  已弃用
// 				};
// //				if(this.couponFlag != '') {
// 				let arr = this.getCouponParams();
// 				params.qrCode = arr;
// //				}
// 				let config = {
// 					url: url,
// 					method: 'POST',
// 					data: params,
// 					headers: {
// 						'sessionId': this.sessionId,
// 					},
// 				};

// 				try{
// 					axios(config).then((res) => {
// 	//					console.log(res.data.data[0], '选择优惠券及时计算金额');
// 	//					console.log(res.data.data[0].goodsTotalMoney, '商品总金额');
// 	//					console.log(res.data.data[0].goodsPromTotalMoney, '优惠后总金额');
// 	//					console.log(res.data.data[0].discountMoney, '优惠金额');
// 	//
// 	//					this.goodsTotalMoney = res.data.data[0].goodsTotalMoney; // 商品金额
// 	//					this.discountMoney = res.data.data[0].discountMoney; // 优惠的金额
// 	//					this.goodsPromTotalMoney = res.data.data[0].goodsPromTotalMoney;
						
// 						console.log(res.data.data[0], '选择优惠券及时计算金额');
// 						console.log(res.data.data[0].promTotalPay, '商品总金额');
// 						console.log(res.data.data[0].realPay, '优惠后总金额');
// 						console.log(res.data.data[0].totalMinis, '优惠金额');
// 						console.log(res.data.data[0].ticketCut, '优惠券优惠');
// 						console.log(res.data.data[0].discountCut, '活动优惠');
						
// 						this.goodsTotalMoney = Number(res.data.data[0].promTotalPay); // 商品金额
// 						this.goodsPromTotalMoney = Number(res.data.data[0].realPay); //优惠后总金额  实付金额
//                         this.discountMoney = Number(res.data.data[0].totalMinis); // 优惠的金额
//                         this.discountMoneyByCoupon = Number(res.data.data[0].ticketCut); //优惠券优惠
//                         this.afterPromTotalMoney = Number(res.data.data[0].discountCut); //活动优惠
// 						this.setOrderFlag(true);  // 获取到金额信息  允许用户点击提交订单按钮
// 						console.log(this.discountMoneyByCoupon, '优惠券优惠1');
// 						console.log(this.afterPromTotalMoney, '活动优1');
// 						hideLoading();
	
// 					})
// 				}catch(err){
// 					hideLoading();
// 				}
// 			},
			goInfomation() {
				this.$router.push({
					path: 'orderInformation',
					query: {
						arr: this.goodsList
					}
				});
			},
			//	       	 展示优惠券
			showCoupon() {
				//				console.log("sss")
				if(this.$refs.coupon){
					this.$refs.coupon.showCover()
				}
			},
			//获取总金额
			getGoodsNum() {
				console.log(this.goodsList,'this.goodsList')
				this.num=0;
				if(this.goodsList.length != 0) {
					for(let i = 0; i < this.goodsList.length; i++) {
//						goodsType == 7  称重散卖
						if(this.goodsList[i].goodsType == 7){
							this.num += 1
						}else{
							this.num += this.goodsList[i].goodsNum;
						}
					}
				}
			},
			goBack() {
				window.history.back();
			},
			checkeParams() {

			},
			getCouponParams() {
				console.log('获取优惠券参数123',this.getTicketList)
				let arr = this.getTicketList;
				let newArr = [];
				for(let i = 0; i < arr.length; i++) {
					newArr.push(arr[i].qrCode);
				}

				let str = newArr.join();
				console.log('拼接优惠券参数',str)
				return str;
			},
			getCipher() {
				let url = window.api.customer_host + "/customer/getCustomer";
				let config = {
					url: url,
					method: "GET",
					headers: {
						sessionId: localStorage.getItem("sessionId")
					}
				}
				axios(config).then((res) => {
					if(res.data.returnCode) {
						console.log(res.data.data[0].walletStatus, '是否设置密码');
						this.walletStatus = res.data.data[0].walletStatus; // 0 代表暂未设置密码   1  代表已经设置密码
						this.moneyWithoutC = res.data.data[0].moneyWithoutCode; //钱包免密金额
					}

				})
			},
			showGiftCard() {
				if(this.walletStatus == 1) {
					this.$refs.giftCard.showCover();
				} else {
					MessageBox.confirm('去设置支付密码').then((action) => {
						console.log(action);
						this.$router.push('SetKeyWallet');
					})
				}

			},
			//是否使用钱包支付  
			checkBuyByCard() {
				var flag = this.getUseGiftCard;
				//      		console.log(flag);
				return flag;
			},
			//判断是否需要填密码
			checkPurse() {
				let flag = this.checkBuyByCard();
				if(flag) {
					var balanceM = Number(this.getAvailAmount); // 钱包可用余额
					var moneyWithoutC = Number(this.moneyWithoutC); // 钱包免密金额
					var totalMoney = Number(this.goodsPromTotalMoney); // 订单应付金额
					console.log(moneyWithoutC, 'en ')
					if(moneyWithoutC == null || moneyWithoutC == undefined || moneyWithoutC == 0) {
						console.log('用户没有设置免密金额，需要验证密码')
						this.$refs.pursekey.showOrHide();
						this.$refs.pursekey.clearKeyall();
						return
					}
					//1 钱包支付金额是否 大于最大免密金额   (可用余额)
					if(balanceM >= totalMoney) {
						//使用 应付金额 判断是否填写密码  订单完成 不用去支付页
						if(totalMoney > moneyWithoutC) {
							//填密码
							//	      				 	this.showMask = true;
							this.$refs.pursekey.showOrHide();
							this.$refs.pursekey.clearKeyall();
							//	      				 	this.setShowMask(true);
						} else {
							//不填密码
							console.log('不用输入密码1');
							this.toPay();
						}

					} else {

						if(balanceM > moneyWithoutC) {
							//填密码
							this.$refs.pursekey.showOrHide();
							this.$refs.pursekey.clearKeyall();
						} else {
							//不填密码
							//							console.log(this.$refs.pursekey);
							this.toPay();
							//	        			 	this.setShowMask(true);
						}
					}
				} else {
					this.toPay();
				}
			},
			//从支付页点返回处理
			checkPayBack(){
				let flag = this.$store.getters.getNativeBackFlagForPay;
				// let flag2 = !this.$route.query || !this.$route.query.res;
				// if(flag && flag2){
				if(flag){
					this.$store.commit("setNativeBackFlagForPay", false);
					this.$router.replace({path:'order',query:{orderStatus:1}});
					return true;
				}
				// else if(!flag){
				// 	this.$router.push({path:'home'});
				// 	return true;
				// }
				return false;
			},
			async toPay() {
				showLoading();
//				console.log(this.getOrderFlag,'打印信息误删')
        		// 判断获取金额信息接口是否已返回数据  没返回就禁止下单
        		// if(!this.getOrderFlag){
        		// 	return;
        		// }
				//防止多次点击下单
				console.log(this.clickFlag,'this.clickFlag1')
        		if(!this.clickFlag){
        			return ;
        		}
				this.clickFlag = false;  // 点击后置为禁用状态
				console.log(this.clickFlag,'this.clickFlag2')
				var that = this;
// 				var myTimer = setTimeout(function(){
// //      			console.log('定时器')
//         			that.clickFlag = true;
//         		},5000)
				let params = {
					storeOrderNo: this.storeOrderNo, //pos机订单编号
//					shopId: this.shopId //门店编码  目前已废弃
					storeCode:this.storeCode,
					token:this.tokens,
//					storeOrderNo:'54564654654654',
//					storeCode:'1613'
				};
//				if(this.couponFlag != '') {
					let arr = this.getCouponParams();
					params.qrCode = arr;
//				}

				console.log(params, '请求参数');
				let config = {
//					url: window.api.trade_host + '/orderOffline/createNotPayOrder',  目前已废弃
					url: window.api.trade_host + '/offLine/createWaitPayOrder',
					method: 'POST',
					data: params,
					headers: {
						'sessionId': this.sessionId,
						'Content-Type': 'application/json',
						'Accept': 'application/json'
					},
				};
				try {
//					axios(config).then((res) => {
						var res =  await axios(config);
						if(res.status == 200) {
							// console.log(res,"接口返回的数据");
							hideLoading()
							if(res.data.returnCode == 1) {
								// console.log('订单生成');
								var orderNo = res.data.data[0].parentOrderNo;
								if(this.totalMoney != 0){
									this.$router.replace({name: "pay", params: {orderNo:orderNo,orderType:xianxia}});
								}else{
									this.$router.replace({name: "paysuccessfully", params: {orderNo:orderNo,orderType:xianxia}});
								}

								//	commonObject.confirm_order = {'orderNo': orderNo, 'realPay': submitInfor.allPrice.replace('￥','')}
								//								var u = navigator.userAgent;

								//								var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
								//								var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
								//								if(isAndroid) {
								//									this.$router.push({name: "apay", params: {orderNo:orderNo,orderType:1}});
								//								} else if(isIOS) {
								////									this.$router.push('ipay/' + orderNo);
								//									this.$router.push({name: "ipay", params: {orderNo:orderNo,orderType:1}});
								//									//	console.log('苹果');
								//								} else {
								////									this.$router.push('apay/' + orderNo);
								//									this.$router.push({name: "apay", params: {orderNo:orderNo,orderType:1}});
								//								}

							} else if(res.data.returnCode == 0){
								this.tokens = res.data.token;
								console.log("this.tokens0",this.tokens)
								Toast({
									message: res.data.msg,
									duration: 2000,
									type: 'fail'
								});
								setTimeout(()=>{
									this.$router.replace({path:'home'});
								},2000)
								
							} else if(res.data.returnCode == 2){
								this.tokens = res.data.token;
								console.log("this.tokens2",this.tokens)
								Toast({
									message: res.data.msg,
									duration: 2000,
									type: 'fail'
								});
								setTimeout(()=>{
									this.$router.replace({path:'home'});
								},2000)
							}else{
								this.tokens = res.data.token;
								console.log("this.tokens3",this.tokens)
								Toast({
									message: res.data.msg,
									duration: 2000,
									type: 'fail'
								});
								setTimeout(()=>{
									this.$router.replace({path:'home'});
								},2000)
							}
							// this.clickFlag = true;  //接口返回  解除点击禁用
						} else {
							this.tokens = res.data.token;
							hideLoading()
							console.log("this.tokens333",this.tokens)
							Toast({
								message: '生成订单失败',
								duration: 2000,
								type: 'fail'
							});
							setTimeout(()=>{
								this.$router.replace({path:'home'});
							},2000)
						}
//					})
				} catch(err) {
					Toast({
						message: '生成订单失败',
						duration: 2000,
						type: 'fail'
					});
					setTimeout(()=>{
						this.$router.replace({path:'home'});
					},2000)
				}
			}
		},
		beforeDestroy() {
			let arr = [];
			hideLoading();
			this.setTicketList(arr);  //清空优惠券
			this.setUseGiftCard(false);
			this.setOrderFlag(false); // 将提交按钮设置为禁用状态
			
			//	    	this.setFpObj({});   // 重置发票对象的在indexvue中实现
		},
		created() {
			console.log("created获取优惠券数据",this.getTicketList)
			if (this.checkPayBack()) return;  //判断从支付页点原生返回 处理
			this.getSmallData(true);
//			this.getCipher(); // 是否设置钱包支付密码
		},
		mounted(){
			//			展示loading
			showLoading();
			setTimeout(() => {
				hideLoading();
			},3000)
		}
	}
</script>

<style scoped="scoped">
	.settle_accounts {
		height: 3rem;
		background: rgba(255, 255, 255, 0.9);
		overflow: hidden;
		position: fixed;
		width: 100%;
		left: 0;
		bottom: -1px;
		display: table;
		border-top: 1px solid #eaeaea;
		z-index: 1;
	}
	
	.scroller_list {
		overflow-y: auto;
	}
	
	.iscroll_list {
		height: 5.5rem !important;
	}
	
	.scroller_list {
		position: relative;
	}
	
	.vue_app {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-between;
	}
	
	.content {
		flex: 1;
		overflow-y: auto;
		width: 100%;
	}
	.choose_list .statistics{
		padding-top: 1.9rem;
	}
	.goodsTopShow{
        opacity: 0.6;
        position: absolute;
        left: 0;top: 0;
        color: #ffffff;
        padding: 0 0.1rem;
        font-size:12px;
    }
    .goodsTopShowBackY{
        background:#faa73c;
    }
    .goodsTopShowBackR{
        background: #EF5423;
    }
</style>